using System.Diagnostics.CodeAnalysis;

namespace KinonekoSoftware.CodariaDB.Documents.Timelines
{
    [SuppressMessage("ReSharper", "RedundantArgumentDefaultValue")]
    public sealed class StoryPoint : RootObject, IComparable<StoryPoint>
    {
        private string _name;
        private string _intro;
        private string _parentID;
        private string _storyID;
        private string _draftId;

        public int CompareTo(StoryPoint other)
        {
            if (other is null)
            {
                return 1;
            }

            var v = Index - other.Index;

            return v == 0 ? 0 :
                v    < 0  ? -1 :
                            1;
        }
        
        public int Index { get; set; }

        /// <summary>
        /// 获取或设置 <see cref="Intro"/> 属性。
        /// </summary>
        public string Intro
        {
            get => _intro;
            set => SetValue(ref _intro, value);
        }

        /// <summary>
        /// 获取或设置 <see cref="Name"/> 属性。
        /// </summary>
        public string Name
        {
            get => _name;
            set => SetValue(ref _name, value);
        }

        public string ParentID
        {
            get => _parentID;
            set
            {
                _parentID = value;
                RaiseUpdated(nameof(ParentID));
                RaiseUpdated(nameof(HasParent));
            }
        }

        public string StoryID
        {
            get => _storyID;
            set
            {
                _storyID = value;
                RaiseUpdated(nameof(StoryID));
                RaiseUpdated(nameof(HasStory));
            }
        }
        
        public string DraftID
        {
            get => _draftId;
            set
            {
                _draftId = value;
                RaiseUpdated(nameof(DraftID));
                RaiseUpdated(nameof(HasDescription));
            }
        }

        [BsonIgnore]
        public bool HasParent => !string.IsNullOrEmpty(_parentID);

        [BsonIgnore]
        public bool HasDescription => !string.IsNullOrEmpty(_draftId);

        [BsonIgnore]
        public bool HasStory => !string.IsNullOrEmpty(_storyID);
    }
}